package com.yingside.collection;

import java.util.HashSet;
import java.util.Set;

public class TestSet {
    public static void main(String[] args) {
        /*Set<String> set = new HashSet<>();
        set.add("aaa");
        set.add("ccc");
        set.add("bbb");
        set.add("kkk");
        set.add("eee");
        set.add("aaa");

        for (String s : set) {
            System.out.println("s = " + s);
        }*/

        Student s1 = new Student(1,"张三1","2423535431");
        Student s2 = new Student(2,"张三2","2423535432");
        Student s3 = new Student(3,"张三3","2423535433");
        Student s4 = new Student(4,"张三4","2423535434");

        Set<Student> sets = new HashSet<>();
        sets.add(s1);sets.add(s2);sets.add(s3);sets.add(s4);
        //注意，引用数据类型，对象重复才叫重复
        sets.add(new Student(4,"张三4","2423535434"));
        //下面的这几个对象，才叫做重复
        sets.add(s1);
        sets.add(s1);
        sets.add(s1);

        //foreach循环，只是用来循环数组和集合的
        for (Student s : sets) {
            System.out.println("s = " + s);
        }

        //由于没有下标，删除方法只能根据对象删除
        sets.remove(s1);

        sets.contains(s2);

    }
}
